# # @Time : 2021/4/7 9:47
# # @Author : Fioman
# # @Phone : 13149920693
# """
# 程序启动之前的安全验证,如果程序已经存在了进程中,或者不是在本机的设备上面,或者是可信的电脑上面.程序就不启动.
# 可信的设备列表自己来定义,首先自己的本机算一个.
# """
# import wmi
# import sys, os
# import win32api, win32con
# import psutil
#
#
# def get_cpu_list():
#     """
#     获取本机的cpu的序列号
#     :return:
#     """
#     wm = wmi.WMI()
#     cpuList = []
#     for cpu in wm.Win32_processor():
#         cpuList.append(cpu.ProcessorId.strip())
#     return cpuList
#
#
# def get_disk_list():
#     """
#     获取系统当前的硬盘的序列号
#     :return:
#     """
#     wm = wmi.WMI()
#     diskList = []
#     for disk in wm.Win32_DiskDrive():
#         diskList.append(disk.SerialNumber.strip())
#     return diskList
#
#
# def verify_device():
#     """
#     检查设备是否是可信的列表,可信的设备列表,先列出来
#     :return:
#     """
#     trustedCpuList = ["BFEBFBFF000906EB","BFEBFBFF000906EA",'BFEBFBFF000906E9']
#     trustedDiskList = ["WD-WX41AC9PE5HR", "184409804273","0000_0000_0000_0000_0000_0100_0000_0000.","WFL55GSW",'511170120137000764  _00000001.']
#     localCpu = get_cpu_list()[0]
#     localDisk = get_disk_list()[0]
#     try:
#         if localCpu not in trustedCpuList and localDisk not in trustedDiskList:
#             win32api.MessageBox(0, "设备不匹配,只能在原厂设备上运行,请联系厂家", '错误', win32con.MB_ICONWARNING)
#             sys.exit(0)
#     except Exception as e:
#         print(str(e))
#         win32api.MessageBox(0, "设备不匹配,只能在原厂设备上运行,请联系厂家", '错误', win32con.MB_ICONWARNING)
#         os._exit(0)
#
#
# # 查看进程,如果存在就告诉用户,在任务管理器中恢复或者杀死重新启动
# def check_exe():
#     pids = psutil.pids()
#     count = 0
#     mvsPidList = []
#     for pid in pids:
#         try:
#             p = psutil.Process(pid)  # 这里有可能会出现异常,有的进程在你实例化的时候可能已经不存在了.
#         except:
#             continue
#         if p.name() == 'hd.exe':
#             count += 1
#         if p.name().lower() == "mvs.exe":
#             mvsPidList.append(pid)
#     if count > 1:
#         win32api.MessageBox(0, "程序已经启动,请在任务管理器中结束所有的其他的进程", '错误', win32con.MB_ICONWARNING)
#         os._exit(0)
#
#     if len(mvsPidList) >= 1:
#         for pidDelete in mvsPidList:
#             cmd = "taskkill /f /pid {}".format(pidDelete)
#             try:
#                 os.system(cmd)
#             except Exception as e:
#                 pass
#
#
#
# if __name__ == '__main__':
#     print("cpu 序列号:{}".format(get_cpu_list()))
#     print("disk 序列号:{}".format(get_disk_list()))
#     check_exe()
